﻿using System;
using System.IO;

namespace myWinForm.Temp.Trash
{
    public class User
    {
        public string Name { get; set; }
        public string Password { get; set; }

    }


    public interface ILog
    {
        void Log(string msg);
    }

    public class ConsoleLog : ILog
    {
        public void Log(string msg)
        {
            Console.WriteLine(msg);
        }
    }

    public class TextLog:ILog{
        public void Log(string msg)
        {
            using (StreamWriter sw = File.AppendText("log.txt"))
            {
                sw.WriteLine(msg);
                sw.Flush();
                sw.Close();
            }
        }
    }



    public class UserService
    {
        public ILog LogStratrgy { get; set; }

        public UserService()
        {
            LogStratrgy = new ConsoleLog();
        }

        public void Register(User user)
        {
            //Log(user.Name == "John" ? "fail" : "register Success");
            if (user.Name == "John")
            {
                LogStratrgy.Log("fail");
            }
            else
            {
                LogStratrgy.Log("success");
            }
        }


        private static void Log(string msg)
        {
            Console.WriteLine(msg);
        }
    }
}